<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // 浅拷贝：只拷贝第一层
        // const  obj = {name:'zs',age:18,children:{name:'老王'}}
        // console.log(obj,'obj');
        // const obj2 = {...obj}  // {name:'zs',age:18,children:{name:'老王'}}
        // console.log(obj2,'obj2');
        // obj2.name = '王五'
        // obj2.children.name = '王八'
        // console.log('-------------------------');
        // console.log(obj2,'obj2');
        // console.log(obj,'obj');

        // 深拷贝：完全拷贝
        const  obj = {name:'zs',age:18,children:{name:'老王'}}
        const obj3 = JSON.parse(JSON.stringify(obj)) // {name:'zs',age:18,children:{name:'老王'}}
        console.log(obj,'obj');
        console.log(obj3,'obj3');
        console.log('------');
        obj3.children.name = '王八'
        console.log(obj,'obj');
        console.log(obj3,'obj3');

        // 简单的数据类型   nubmer,string,boolean undefined,null   深拷贝和浅拷贝没有任何区别
        // 复杂数据类型    Array, {}-->Object   浅拷贝：只拷贝第一层  ,       // 深拷贝：完全拷贝

    </script>
</head>
<body>

</body>
</html>
